# -*- mode: python ; coding: utf-8 -*-

import os
from PyInstaller.utils.hooks import collect_data_files, collect_submodules

# 获取当前目录
current_dir = os.path.dirname(os.path.abspath(SPEC))

# 主程序分析
a = Analysis(
    ['main.py'],
    pathex=[current_dir],
    binaries=[],
    datas=[
        # 配置文件和数据文件
        ('config.ini', '.'),
        ('data', 'data'),
        ('components/res', 'components/res'),
        
        # UI文件
        ('components/*.ui', 'components'),
        
        # JavaScript文件
        ('captcha/js', 'captcha/js'),
        
        # node.exe文件 (如果存在)
        ('components/res/node.exe', 'components/res'),
        
        # 配置模板
        ('components/res/template', 'components/res/template'),
    ],
    hiddenimports=[
        # PyQt5相关模块
        'PyQt5.QtCore',
        'PyQt5.QtGui', 
        'PyQt5.QtWidgets',
        'PyQt5.sip',
        
        # 项目模块
        'captcha.captcha',
        'captcha.gap', 
        'captcha.space_inference',
        'components.captcha_ui',
        'components.login_ui',
        'components.main_ui_modern',
        'components.main_ui',
        'utils.config',
        'utils.encrypt',
        'utils.logger',
        'utils.path',
        'utils.utils',
        'utils.voice_reminder',
        'zhihuishu.auth',
        'zhihuishu.course',
        'zhihuishu.study',
        
        # 第三方库
        'requests',
        'numpy',
        'cv2',
        'Crypto.Cipher.AES',
        'Crypto.Util.Padding',
        'execjs',
        'asyncio',
        'base64',
        'json',
        'configparser',
        'logging',
        'datetime',
        'threading',
        'time',
        'os',
        'sys',
        'ctypes',
        
        # 语音提醒相关
        'pyttsx3',
        'pyttsx3.drivers',
        'pyttsx3.drivers.sapi5',
        'pyttsx3.drivers.nsss',
        'pyttsx3.drivers.espeak',
        'win32com.client',
        'win32api',
        'win32con'
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[
        # 排除不需要的模块以减小体积
        'tkinter',
        'matplotlib',
        'IPython',
        'jupyter',
        'pandas',
        'scipy',
        'PIL',
        'test',
        'tests',
        'unittest'
    ],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=None,
    noarchive=False,
)

# 生成PYZ压缩包
pyz = PYZ(a.pure, a.zipped_data, cipher=None)

# 生成可执行文件
exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='智慧树刷课神器',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,  # 设置为False隐藏控制台窗口
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon='components/res/images/icon.png'  # 设置程序图标
)

# 收集所有文件到dist目录
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='zhihuishu'
)
